package com.itheima.tliasmanager.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tliasmanager.mapper.StudentMapper;
import com.itheima.tliasmanager.pojo.Vo.PageResult;
import com.itheima.tliasmanager.pojo.Dto.QueryParam;
import com.itheima.tliasmanager.pojo.domain.Student;
import com.itheima.tliasmanager.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageResult<Student> pageList(QueryParam queryParam) {
        log.info("分页查询学生列表,参数:{}",queryParam);
        PageHelper.startPage(queryParam.getPage(),queryParam.getPageSize());
        Page<Student> page = (Page<Student>) studentMapper.pageList(queryParam);
        return new PageResult<>(page.getTotal(),page.getResult());
    }

    @Override
    public void batchRemoveStudent(List<Integer> ids) {
        log.info("S--->批量删除学生,ids:{}",ids);
        studentMapper.deleteByIds(ids);
    }

    @Override
    public void addStudent(Student student) {
        log.info("S--->添加学生,参数:{}",student);
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.inster(student);
    }

    @Override
    public Student getById(Integer id) {
        log.info("S--->查询学生,id:{}",id);
        Student student = studentMapper.getById(id);
        return student;
    }

    @Override
    public void updateStudent(Student student) {
        log.info("S--->更改学生,参数:{}",student);
        studentMapper.updateStudent(student);
    }

    @Override
    public void updateStudentViolation(Integer id, Short score) {
        log.info("S--->更新学生违规信息,id:{},score:{}",id,score);
        studentMapper.updateStudentViolation(id,score);
    }

}
